<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>海角论坛</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="fly,layui,前端社区">
    <meta name="description" content="Fly社区是模块化前端UI框架Layui的官网社区，致力于为web开发提供强劲动力">
    <link rel="stylesheet" href="../../static/res/layui/css/layui.css">
    <link rel="stylesheet" href="../../static/res/css/global.css">
</head>
<body>
<meta name="referrer" content="no-referrer">
<div class="fly-header layui-bg-black">
    <div class="layui-container">
        <a class="fly-logo" href="/">
            <img src="../../static/res/images/logo.png" alt="layui">
        </a>

        <ul class="layui-nav fly-nav-user" id="ul_user">

            <!-- 登入后的状态 -->
            {%if user%}
            <li class="layui-nav-item">
              <a class="fly-nav-avatar" href="javascript:;">
                <cite class="layui-hide-xs">{{user.nick_name}}</cite>
                <i class="iconfont icon-renzheng layui-hide-xs" title="认证信息：南神"></i>
                  {%if user.is_vip != 0%}
                <i class="layui-badge fly-badge-vip layui-hide-xs">VIP{{user.is_vip}}</i>
                  {%endif%}
                <img src="{{user.avatar_url}}">
              </a>
              <dl class="layui-nav-child">
                <dd><a href="/user/set"><i class="layui-icon">&#xe620;</i>基本设置</a></dd>
                <dd><a href="/user/follow"><i class="iconfont icon-tongzhi" style="top: 4px;"></i>我的关注</a></dd>
                <dd><a href="/user/home?u={{user.id}}"><i class="layui-icon" style="margin-left: 2px; font-size: 22px;">&#xe68e;</i>我的主页</a></dd>
                <hr style="margin: 5px 0;">
                <dd><a href="/user/logout" style="text-align: center;">退出</a></dd>
              </dl>
            </li>
            {%else%}
                        <!-- 未登入的状态 -->
            <li class="layui-nav-item">
                <a class="iconfont icon-touxiang layui-hide-xs" href="/login"></a>
            </li>
            <li class="layui-nav-item">
                <a href="/login">登录</a>
            </li>
            <li class="layui-nav-item">
                <a href="/reg">注册</a>
            </li>
            {%endif%}
        </ul>
    </div>
</div>

    <div class="fly-msg" style="margin-top: 15px;height: 500px;text-align: center">
      <p>支付系统正在准备接入，敬请期待</p>
    </div>

<div class="fly-footer">
    <p><a href="#">海角论坛</a> 2019 &copy; <a href="#">葫芦娃出品</a></p>
</div>

<script src="../../static/json/jquery-3.3.1.min.js"></script>
<script src="../../static/js/jquery-3.3.1.js"></script>
<script src="../../static/res/layui/layui.js"></script>
<script src="../../static/js/jwt.js"></script>
<script src="../../static/res/mods/detail.js"></script>
<script>
    $(function () {
        hasUser();

    });

    function hasUser(){

        let jwt = getJwtToken();
        if (jwt) {
            $.ajax({
                type:"get",
                url: HOST_URL + "user/getUser",
                dataType: "json",
                headers: createAuthorizationTokenHeader(),
                success:function (data) {
                    console.log(data);
                    if (data) {
                        let appendVal = `
                            <li class="layui-nav-item">
                              <a class="fly-nav-avatar" href="javascript:;">
                                <cite class="layui-hide-xs">${data.username}</cite>
<!--                                <i class="iconfont icon-renzheng layui-hide-xs" title="认证信息：layui 作者"></i>-->
                                <i class="layui-badge fly-badge-vip layui-hide-xs">VIP${data.level}</i>
                                <img src="${data.picture}">
                              </a>
                              <dl class="layui-nav-child">
                                <dd><a href="../user/set.html"><i class="layui-icon">&#xe620;</i>基本设置</a></dd>
                                <dd><a href="../user/message.html"><i class="iconfont icon-tongzhi" style="top: 4px;"></i>我的消息</a></dd>
                                <dd><a href="../user/home.html"><i class="layui-icon" style="margin-left: 2px; font-size: 22px;">&#xe68e;</i>我的主页</a></dd>
                                <hr style="margin: 5px 0;">
                                <dd><a href="javascript:logout();" style="text-align: center;">退出</a></dd>
                              </dl>
                            </li>
                        `;

                        $("#ul_user").html(appendVal);
                    }
                }
            })
        }
    }
    //  注销
    function logout() {
        layer.confirm("真的要注销吗?", () => {

            removeJwtToken();
            layer.msg("注销成功", {time: 1000}, function () {
                location.reload();
            });
        })
    }
    function dianji(e) {
        document.getElementById("diji" + e).click()
    }

    function aaa(e) {
		var content= document.getElementById("L_content" + e).value;
        var reply_id = document.getElementById("reply_id" + e).value;   // 获取这条评论回复的是谁的评论
        var news_id = document.getElementById("tie_id").value;
		if (!content) {
            //如果回复的内容没有数据则弹窗
            alert("你还没有评论。。。。");
            return;
        }
        var params = {
            "content": content,
            "reply_id": reply_id,
            "news_id": news_id};

		$.ajax({
            url: "/user/reply",
            type: "post",
            data: JSON.stringify(params),
            contentType: "application/json",
            success: function (resp) {
            if (resp.errno == "0") {
                   location=location
                }
                else if (resp.errno == "8009"){
                    alert(resp.msg)
                    location.href="/login"
                }
                else if (resp.errno == "9006"){
                    alert(resp.msg)
                    location.href="/user/index"
                }
                else {
                    alert(resp.msg)
                }
            }
        })
    }
    function shoc(e) {
    var zl = document.getElementById("sc").value;
        var params = {
            "zl": zl,
            "news_id": e
        };
        $.ajax({
            url: "/user/collect",
            type: "post",
            data: JSON.stringify(params),
            contentType: "application/json",
            success: function (resp) {
                if (resp.errno == "0") {
                   location=location
                }
                else {
                    alert(resp.msg)
                }
    }})
    }
</script>

</body>
</html>